package com.foo.Businesstest;

import static org.junit.Assert.assertEquals;

import java.rmi.RemoteException;

import org.apache.axis2.AxisFault;
import org.example.www.globalsearch.GetAllData;
import org.example.www.globalsearch.GetAllDataResponse;
import org.globalSearchexample.ws.GetAllDataFaultException;
import org.globalSearchexample.ws.GlobalSearchService;
import org.globalSearchexample.ws.GlobalSearchStub;
import org.junit.Test;
import org.movieexample.ws.GetAllMovieDataFaultException;
import org.movieexample.ws.MovieServiceStub;
import org.movieexample.www.movie.GetAllMovieData;
import org.movieexample.www.movie.GetAllMovieDataResponse;


public class GlobalSearchTest 
{
	@Test
	public void getAllData() throws GetAllDataFaultException
	{
		GlobalSearchService service = new GlobalSearchService();
		GetAllData getAllData = new GetAllData();
		getAllData.setIn("");
		GetAllDataResponse response =  service.getAllData(getAllData);
		
		assertEquals(50,response.getOut().getRestaurantData().getRestaurant().length);
		//assertEquals(70,response.getOut().getMovieData().getMovie().length);
		
	}
	
	private static final String GLOBAL_SERVICE_END_POINT ="http://localhost:8080/axis2/services/GlobalSearch";
	public GlobalSearchStub gStub;
	//Network Call
	@Test
	public void getAllDataByNetwork() throws GetAllDataFaultException
	{
		try {
			gStub = new GlobalSearchStub(GLOBAL_SERVICE_END_POINT);
		} catch (AxisFault e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		GetAllData getDataParam = new GetAllData();
		getDataParam.setIn("");
		GetAllDataResponse res= new GetAllDataResponse();
		try {
			res = gStub.getAllData(getDataParam);
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (GetAllDataFaultException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		assertEquals(50,res.getOut().getRestaurantData().getRestaurant().length);
		//assertEquals(70,res.getOut().getMovieData().getMovie().length);
	}
	
	private static final String MOVIES_SERVICE_END_POINT = "http://localhost:8080/axis2/services/MovieService";
	public MovieServiceStub mStub;
	@Test
	public void getAllMovieData() 
	{
		try {
			mStub = new MovieServiceStub(MOVIES_SERVICE_END_POINT);
		} catch (AxisFault e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		GetAllMovieData getDataParam = new GetAllMovieData();
		getDataParam.setIn("");
		GetAllMovieDataResponse res= new GetAllMovieDataResponse();
		try {
			res = mStub.getAllMovieData(getDataParam);
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (GetAllMovieDataFaultException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		assertEquals(70,res.getOut().getMovies().length);
	}

}

